home *** CD-ROM | disk | FTP | other *** search
- //-------------------------------------
- //
- // SuperCode (c) 1996 by T.Kühn
- //
- // Programmiersprache: ANSI-C
- // Projektstart: 30.07.95
- //
- // Modul: Score
- //
- //-------------------------------------
-
-
-
- #include <pragma/intuition_lib.h>
- #include <pragma/graphics_lib.h>
- #include <pragma/exec_lib.h>
- #include <pragma/dos_lib.h>
- #include <struct.h>
-
-
- //-------------------------------------
-
- struct tkList highscores;
-
- UBYTE str_day[LEN_DATSTRING+2];
- UBYTE str_date[LEN_DATSTRING+2];
- UBYTE str_time[LEN_DATSTRING+2];
-
- struct DateTime date;
-
- UBYTE file_name[]="PROGDIR:SuperCode.score";
-
- struct Window *window_score=0;
-
- struct ScoreData
- {
- struct RastPort *rp;
- ULONG x,y,w,y2;
- ULONG count;
- };
-
- struct Score *score_last=0;
- void score_windowopen();
-
- //-------------------------------------
- void score_savenode(struct Score *score_org,struct tkfile *file)
- {
- const ULONG l=sizeof(struct Score);
- ULONG t;
- BYTE score[l+2];
-
- memcpy(score,score_org,l);
-
- file_write(file,"NEXT",4);
-
- for (t=0;t<l;t++)
- {
- score[t]^=t+0xEB;
- }
-
- file_write(file,score,l);
-
- }
- //-------------------------------------
- void score_save()
- {
- struct tkfile *file;
-
- file = file_open(file_name,MODE_NEWFILE,FALSE);
- if (file)
- {
- List_DoAll(&highscores,(APTR)score_savenode,(APTR)file);
- }
- file_free(&file);
-
- }
- //-------------------------------------
- void score_load()
- {
- struct tkfile *file;
-
- file = file_open(file_name,MODE_OLDFILE,ASKFILE_CANTOPEN);
- {
- const ULONG l=sizeof(struct Score);
- ULONG t;
- BYTE dummy[6],*new;
-
- while(file->ok)
- {
- dummy[0]=0;
- file_read(file,dummy,4);
- if (0!=strncmp(dummy,"NEXT",4)) break;
-
- new=Memory_Alloc(l);
- file_read(file,new,l);
-
- for (t=0;t<l;t++)
- {
- new[t]^=t+0xEB;
- }
- List_AddTail(&highscores,(APTR)new);
- }
- }
- file_free(&file);
- }
- //-------------------------------------
-
-
- //-------------------------------------
- long score_compare(struct Score *score1,struct Score *score2)
- {
- LONG back=0;
-
- if (score1->score > score2->score) back=-1;
- if (score1->score < score2->score) back= 1;
-
- if (back==0)
- {
- if (score1->time < score2->time) back=-1;
- if (score1->time > score2->time) back= 1;
- }
-
- return back;
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void score_output(struct Score *score,struct ScoreData *data)
- {
- UBYTE text[200],*text_order;
- ULONG c;
-
- ULONG t=score->time;
- ULONG h=(t/3600);
- ULONG m=(t-h*3600)/60;
- ULONG s=(t-m*60+h*3600);
-
- if (data->y < data->y2)
- {
- if (score_last!=score)
- {
- c=Scrn.DrawInfo->dri_Pens[TEXTPEN];
- }
- else
- {
- c=Scrn.DrawInfo->dri_Pens[SHINEPEN];
- }
-
- switch (score->order)
- {
- case ORDER_POS: text_order=CatStr(TXT_PREFPOSITION);break;
- case ORDER_DESC: text_order=CatStr(TXT_PREFDESC);break;
- case ORDER_RANDOM: text_order=CatStr(TXT_PREFRANDOM);break;
- }
-
- memcpy(&date.dat_Stamp,&score->date,sizeof(struct DateStamp));
- date.dat_Format=FORMAT_CDN;
- date.dat_Flags=DTF_SUBST;
- date.dat_StrDay = str_day;
- date.dat_StrDate = str_date;
- date.dat_StrTime = str_time;
- DateToStr(&date);
-
- sprintf(text,"%2.2d %-10.10s %9.9d %2.2d:%02.2d:%02.2d %8.8s %2.2d %2.2d %2.2d %2.2d %6.6s",data->count++,score->name,score->score,h,m,s,str_date,score->lines,score->colors,score->columns,score->equals,text_order);
-
- Txt_PrintFit(data->rp,text,0,data->x,data->y,data->w,0,c,Scrn.DrawInfo->dri_Pens[BACKGROUNDPEN],BOX_LEFT);
-
- data->y+=data->rp->TxHeight+2;
- }
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void score_display()
- {
- score_windowopen();
- {
- struct Window *win=window_score;
- struct RastPort *rp=window_score->RPort;
- ULONG x=win->BorderLeft+4;
- ULONG y=win->BorderTop+4;
- ULONG w=win->Width-win->BorderLeft-win->BorderRight-8;
- ULONG y2=win->Height-win->BorderBottom-rp->TxHeight-8;
- struct ScoreData data={rp,x,y,w,y2,1};
-
- SetAPen(rp,Scrn.DrawInfo->dri_Pens[BACKGROUNDPEN]);
- RectFill(rp,x,y,x+w,y2);
-
- Txt_PrintFit(rp,CatStr(TXT_SCORETITLE),0,x,y,w,0,Scrn.DrawInfo->dri_Pens[HIGHLIGHTTEXTPEN],Scrn.DrawInfo->dri_Pens[BACKGROUNDPEN],BOX_CENTER);
-
- data.y+=rp->TxHeight+4;
- data.count=1;
-
- List_DoAll(&highscores,(APTR)score_output,(APTR)&data);
- }
-
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void score_windowopen()
- {
- if (!window_score)
- {
- window_score=OpenWindowTags(0,
- WA_Title,CatStr(TXT_SCOREWINTITLE),
-
- WA_Left,prg_prefs->win.score.Xpos,
- WA_Top,prg_prefs->win.score.Ypos,
- WA_Width,prg_prefs->win.score.WinW,
- WA_Height,prg_prefs->win.score.WinH,
- (Scrn.Scrn && Scrn.FlgPublic==FALSE) ? WA_CustomScreen : WA_PubScreen,Scrn.Scrn,
- WA_Flags,
- WFLG_ACTIVATE|
- WFLG_CLOSEGADGET|
- WFLG_DRAGBAR|
- WFLG_DEPTHGADGET|
- WFLG_NEWLOOKMENUS|
- WFLG_RMBTRAP|
- // WFLG_SIZEBBOTTOM|
- WFLG_SIZEBRIGHT|
- WFLG_SIZEGADGET|
- 0,
- WA_IDCMP,
- IDCMP_GADGETUP|
- IDCMP_CLOSEWINDOW|
- IDCMP_NEWSIZE|
- 0,
- // WA_Zoom,0,
- WA_AutoAdjust,TRUE,
- WA_MaxWidth,-1,
- WA_MaxHeight,-1,
- WA_MinWidth,50,
- WA_MinHeight,50,
- TAG_END);
- }
- }
- //-------------------------------------
- void score_windowclose()
- {
- if (window_score)
- {
- window_close(window_score,&prg_prefs->win.score);
- window_score=0;
- }
- }
- //-------------------------------------
-
-
- //-------------------------------------
- LONG score_getbit()
- {
- LONG bit=0;
-
- if (window_score)
- {
- bit=1 << window_score->UserPort->mp_SigBit;
- }
-
- return bit;
- }
- //-------------------------------------
- VOID score_domsg()
- {
- struct Window *win=window_score;
- struct IntuiMessage *msg;
-
- struct Gadget *gadg;
- LONG clas;
- LONG code;
- LONG qual;
- LONG posx,posy,seco,micr;
-
- while (window_score && (msg=(struct IntuiMessage*)GetMsg(win->UserPort)))
- {
- gadg = (APTR)msg->IAddress;
- clas = msg->Class;
- code = msg->Code;
- qual = msg->Qualifier;
- posx = msg->MouseX;
- posy = msg->MouseY;
- seco = msg->Seconds;
- micr = msg->Micros;
-
- ReplyMsg((struct Message*)msg);
-
- switch (clas)
- {
- case IDCMP_CHANGEWINDOW:
- // Window_StoreSize(MsgBlk);
- break;
- case IDCMP_RAWKEY:
- break;
- case IDCMP_NEWSIZE:
- score_display();
- break;
- case IDCMP_MENUPICK:
- // Command_Menu(MsgBlk,GadMsg.Code);
- break;
- case IDCMP_CLOSEWINDOW:
- score_windowclose();
- break;
- case IDCMP_GADGETUP:
- // score_dogadget(gadg->GadgetID,qual);
- break;
- case IDCMP_INACTIVEWINDOW:
- break;
- }
- }
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void score_add(struct Field *player,UBYTE *name)
- {
- struct Score *score;
-
- if (player->finish)
- {
- score=(struct Score*)Memory_Alloc(sizeof(struct Score));
-
- score_last=score;
-
- score->score=code_getpoints(player);
- score->columns=player->columns;
- score->colors=player->num_colors;
- score->equals=player->max_equal;
- score->lines=player->lines;
- score->time=player->sec_finish - player->sec_start;
- score->order=player->val_order;
-
- strncpy(score->name,name,MAX_PLAYERNAME);
-
- DateStamp(&score->date);
-
- List_AddSort(&highscores,&score->node,(APTR)score_compare);
-
- // List_AddTail(&highscores,&score->node);
- // List_Sort(&highscores,(APTR)score_compare);
-
- score_save();
- score_display();
- }
- }
- //-------------------------------------
-
-
- //-------------------------------------
- void score_init()
- {
- List_Init(&highscores,NT_SCORE,0);
- score_load();
- }
- //-------------------------------------
- void score_free()
- {
- score_windowclose();
-
- List_Free(&highscores);
- }
- //-------------------------------------
-
-